﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using YuuzleComic.BLL;
using System.Data;

public partial class admin_pic_downall : Page//YuuzleComic.Web.UI.ManagePage
{
    zj zjbll = new zj();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

        }
    }

    private DataTable GetDownloadList(DataTable dt1)
    {
        DataTable dt = dt1.Copy();
        dt.Columns.Add("no_tpurl");
        dt.Columns.Add("tpcount");
        if (dt.Rows.Count > 0)
        {
            foreach (DataRow dr in dt.Rows)
            {
                List<string> notpurllist = new List<string>();
                if (!System.IO.Directory.Exists(Server.MapPath("~/comicdata/" + dr["tpadd"])))//章节文件夹不存在
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath("~/comicdata/" + dr["tpadd"]));
                }
                string[] tpurl = dr["tpurl"].ToString().Trim().Split('|');
                int tpcount = 0;
                foreach (string url in tpurl)
                {
                    string filename = "/comicdata/" + dr["tpadd"] + (url.Contains("/") ? url.Substring(url.LastIndexOf("/")) : url);
                    if (!System.IO.File.Exists(Server.MapPath("~" + filename)))
                    {
                        notpurllist.Add(url);
                    }
                    else
                    {
                        tpcount ++;
                    }
                }
                dr["no_tpurl"] = string.Join("|", notpurllist.ToArray());
                dr["tpcount"] = tpcount;
            }
        }
        return dt;
    }

    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        if (Request.QueryString["id"] != null)
        {
            DataSet ds = zjbll.GetList(zjGridView.PageSize, e.NewPageIndex, "cid=" + Request.QueryString["id"]);
            zjGridView.DataSource = this.GetDownloadList(ds.Tables[0]);
            zjGridView.DataBind();
            AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[1].Rows[0]["Total"]);
        }
    }
}